package cn.t12.qg.userconsumer.exception;

import com.qg.dto.ReturnResult;
import com.qg.dto.ReturnResultUtils;
import com.qg.exception.QgException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class QgUserExceptionAdvice {

    /**
     * 处理 QgException
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(QgException.class)
    public ReturnResult handleQgException(QgException ex){
        ex.printStackTrace();
        return ReturnResultUtils.returnFail(ex.getCode(),ex.getMessage());
    }

    /**
     * 处理其他Exception
     * @param ex
     * @return
     */
    @ResponseBody
    @ExceptionHandler(Exception.class)
    public ReturnResult handleException(Exception ex){
        ex.printStackTrace();
        return ReturnResultUtils.returnFail(-1,ex.getMessage());
    }
}
